package com.snail.cloud.controller;

import cn.hutool.core.util.IdUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * Resilience4j断路器熔断降级
 *
 * @author snail
 * @date 2024/9/29
 */
@RestController
public class PayCircuitController {

    /**
     * CircuitBreaker 测试
     *
     * @param id ID
     * @return {@link String }
     * @author Snail
     * @date 2024/09/29
     */
    @GetMapping("/pay/circuit/{id}")
    public String myCircuit(@PathVariable("id") Integer id) {
        if (id < 0) throw new RuntimeException("id不能为负数");
        if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "hello circuitBreaker,id: " + id + "\t" + IdUtil.simpleUUID();
    }
}
